package com.base.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.Criterion;
import org.springframework.transaction.annotation.Transactional;

import com.base.exceptions.DaoException;

@Transactional(readOnly=false)
public interface GenericDao<T extends Serializable, KeyType extends Serializable> extends Serializable {
	//--- ABM
	public void add(T entity) throws DaoException;
	public void merge(T entity) throws DaoException;
	public void set(T entity) throws DaoException;
	public void del(T entity) throws DaoException;
	public void deleteById(KeyType id) throws DaoException;
	public void deleteAll() throws DaoException;
	public void deleteQuery(String condition);
	
	//--- Consulta
	public long count() throws DaoException;
	public T get(KeyType id) throws DaoException;
	public T getByCodigo(Object codigo) throws DaoException;
	public T getUnique(String campoUnique, Object valorUnique) throws DaoException;

	public List<T> getAll() throws DaoException;
	public List<T> getByQuery(Map<String, Object> filtros);
	public List<T> getByQuery(T entity) throws DaoException;
	public T getByQueryUnique(T entity) throws DaoException;
	public List<T> getByCriteria(Criterion... criterion);

	//--- Con paginacion
	public List<T> getAll(int firstRow, int maxResult) throws DaoException;
	public List<T> getByQuery(Map<String, Object> filtros, int firstRow, int maxResult) throws DaoException;
	public List<T> getByQuery(T entity, int firstRow, int maxResult) throws DaoException;
	public List<T> getByCriteria(int firstRow, int maxResult, Criterion... criterion);

	//--- Lazy
	public List<T> getByConsulta(Map<String, Object> filtros, Integer firstResult, Integer maxResults, 
									String sortField, String sortOrder, Object count);
}
